import { ref, reactive, watch } from 'vue';
import type {
  ProjectDetailStateForm,
  ViewBasicSetting,
  ViewAnnoSetting,
  ViewDataSetting,
  ViewAnnoUserSetting,
  SeriesDataItem,
} from '@/store/modules/projectDetail/type';
import * as ApiTypes from '@/api/project/project.d';
interface Prop {
  id: string;
  layout: string;
  status: string;
  type: string;
  disabled: boolean;
  form: { basicSetting: ViewBasicSetting; annoSetting: ViewAnnoSetting };
  commonList: ApiTypes.CommonConfigResponse;
  compTotal: number;
  compList: ApiTypes.CompConfigItem[];
  toolList: ApiTypes.ToolConfigItem[];
  lesionList: ApiTypes.LesionConfigItem[];
  watchFormData: Function;
  getFormLeisonDataList: Function;
  clearLesionList: Function;
  getCompData: Function;
  getCompDialog: Function;
  sortAlertTableData: Function;
  clearAlertTableData: Function;
  setSelectCheckAll: Function;
  clearSelectCheckAll: Function;
}
interface CheckItem {
  [x: number]: {
    indeterminate: boolean;
    checked: boolean;
    page: number;
  };
}
const useDetail = (props: Prop) => {
  const functionExecuted = ref(false);
  const current = ref(1);
  const checkArr = ref({});
  const visible = ref(false);
  const getCheckAllList = () => {
    const checkAllNum = Math.ceil(props.compTotal / 10);
    for (let index = 1; index <= checkAllNum; index++) {
      checkArr.value[index] = {
        indeterminate: false,
        checked: false,
        page: index,
      };
    }
  };
  if (!functionExecuted.value) {
    getCheckAllList();
    functionExecuted.value = true;
  }
  const handleClick = () => {
    props.getCompDialog(props.form.annoSetting.seriesFcList, true);
    visible.value = true;
  };
  const handleUpdateVisible = () => {
    visible.value = false;
  };
  const handlePageChange = (page: number) => {
    current.value = page;
    props.getCompData(page);
  };
  const handleChange = (
    value: boolean,
    item: { indeterminate: boolean; checked: boolean; page: number }
  ) => {
    item.indeterminate = false;
    item.checked = value;
    value && props.setSelectCheckAll(true);
    !value && props.clearSelectCheckAll(true);
  };
  return {
    functionExecuted,
    current,
    checkArr,
    visible,
    handleClick,
    handleUpdateVisible,
    handlePageChange,
    handleChange,
  };
};

export default useDetail;
